import { baseUrlApi, requestClient, type Result } from '#/api/request';

/** 获取列表 */
export const getCategory = (params?: object) => {
  return requestClient.get<Result>(baseUrlApi('/portal/admin/category'), {
    params,
  });
};

/** 添加 */
export const postCategory = (data?: object) => {
  return requestClient.post<Result>(baseUrlApi('/portal/admin/category'), data);
};

/** 获取信息 */
export const getCategoryInfo = (data: { id: number }) => {
  return requestClient.get<Result>(
    baseUrlApi(`/portal/admin/category/${data.id}`),
  );
};

/** 编辑 */
export const putCategory = (data?: any) => {
  return requestClient.put<Result>(
    baseUrlApi(`/portal/admin/category/${data.id}`),
    data,
  );
};


export const putCategorySort = (data?: any) => {
  return requestClient.put<Result>(
    baseUrlApi(`/portal/admin/category/updateSort`),
    data,
  );
};



/** 删除 */
export const deleteCategory = (data?: any) => {
  return requestClient.delete<Result>(
    baseUrlApi(`/portal/admin/category/${data.id}`),
    data,
  );
};

/** 设置显示状态 */
export const postCategoryStatus = (data: { id: number; status: number }) => {
  return requestClient.post<Result>(
    baseUrlApi(`/portal/admin/category/${data.id}/status/${data.status}`),
    data,
  );
};

/** 获取列表 */
export const getCategorySelectData = () => {
  return requestClient.get<Result>(
    baseUrlApi('/portal/admin/category/select/data'),
  );
};

//根据code得到树形tree
export const getTreeByCode = (data?: object) => {
  return requestClient.post<Result>(baseUrlApi('/portal/admin/category/getTreeByCode'), data);
};



